package ca.polymtl.rubikcube.CubeActivity;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.view.MotionEvent;
import ca.polymtl.rubikcube.CubeActivity.CubeSurfaceViewRenderer.AnimationCompleteCallback;
import ca.polymtl.rubikcube.CubeActivity.model.Rubik;
import ca.polymtl.rubikcube.CubeActivity.model.Rubik.RotationDirection;
import ca.polymtl.rubikcube.CubeActivity.model.Side;

public class CubeSurfaceView extends GLSurfaceView {
	private CubeSurfaceViewRenderer _renderer;
	final static String LOG_TAG = CubeSurfaceView.class.getSimpleName();

	public CubeSurfaceView(Context context, AttributeSet attr) {
		super(context, attr);
		_renderer = new CubeSurfaceViewRenderer(context);
		setRenderer(_renderer);
	}

	@Override
	public boolean onTouchEvent(final MotionEvent event) {
		queueEvent(new Runnable() {
			public void run() {
				_renderer.touchEventAction(event);
			}
		});
		return true;
	}

	public void rotateFace(Side side, RotationDirection direction) {
		_renderer.rotateFace(side, direction);
	}
	
	public void finishRotateFace() {
		_renderer.finishRotateFace();
	}

	@Override
	protected void onSizeChanged(int w, int h, int oldw, int oldh) {

	}
	
	public void setRubik(Rubik rubik) {
		_renderer.setRubik(rubik);
	}

	public void setAnimationCompleteCallback(AnimationCompleteCallback callback) {
		_renderer.setAnimationCompleteCallback(callback);
	}

}
